package com.huawei.springboot2023.business.goods.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.huawei.springboot2023.business.goods.dto.Goods;
import com.huawei.springboot2023.business.goods.mapper.GoodsMapper;
import com.huawei.springboot2023.business.goods.service.IGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huawei.springboot2023.core.dto.MyPageBand;
import com.huawei.springboot2023.core.dto.MyPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZhouChengYang
 * @since 2023-04-07
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {
    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public MyPager<Goods> myPage(Goods goods, MyPageBand pageBand) {


        // 定义一个自定义分页接口
        IPage<Goods> pages = goodsMapper.myPage(PageDTO.of(pageBand.getPage(),pageBand.getSize()),goods);

        // 根据分页的结果封装返回数据
        MyPager<Goods> pager = new MyPager<>();
        pager.setTotal(pages.getTotal());
        pager.setPage(pageBand.getPage());
        pager.setPageSize(pageBand.getSize());
        pager.setRows(pages.getRecords());

        return pager;

    }
}
